package top.boycharse.talker.service;

import com.google.common.base.Strings;
import top.boycharse.talker.bean.api.account.AccountRspModel;
import top.boycharse.talker.bean.api.base.ResponseModel;
import top.boycharse.talker.bean.api.user.UpdateInfoModel;
import top.boycharse.talker.bean.card.UserCard;
import top.boycharse.talker.bean.db.User;
import top.boycharse.talker.factory.UserFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.SecurityContext;

@Path("/user")
public class UserService extends BaseService{

    // 用户信息修改接口
    // 返回自己的个人信息
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public ResponseModel<UserCard> update(UpdateInfoModel model){
        if (!UpdateInfoModel.check(model)) {
            return ResponseModel.buildParameterError();
        }

        User user = getSelf();
        user = model.updateToUser(user);
        user = UserFactory.update(user);
        UserCard card = new UserCard(user, true);
        return ResponseModel.buildOk(card);

    }
}
